/**
 * Copyright (C) 2015-2018 IQIYI
 * All rights reserved.
 *
 * Author     : 王海斌
 * E-mail     : wanghaibin@qiyi.com
 * Version    :
 * Date       : Thu 13 Aug 2020 11:52:36 AM CST
 * Destription:
 */

#include <iostream>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <malloc.h>

void test_part_virt(int len) {
    int i = len+1;
    char p[1024*1024*i*10];
    memset(p, 0, 1024*1024*i*10);
    printf("currlwent i=%d, p=%p\n", i, p);
    //char *p = new char[1024*1024*i*10];
    //printf("currlwent i=%d, p=%p\n", i, p);
    //memset(p, 0, 1024*1024*i*10);
    //delete [] p;
}

int main() {
#if M_MMAP_MAX
    printf("find M_MMAP_MAX =%d \n", M_MMAP_MAX);
#else
    printf("not find M_MMAP_MAX\n");
#endif

#if HAVE_MALLOPT
    printf("find HAVE_MALLOPT =%d \n", HAVE_MALLOPT);
#else
    printf("not find HAVE_MALLOPT\n");
#endif
    //char * p = new char [1024*1024*512];
    //memset(p, 0, 1024*1024*512);
    //memset(p + 1024*1024*128, 0, 1024*1024*128);
    mallopt(M_MMAP_MAX, 0); // 禁止malloc调用mmap分配内存
    char p[1024*1024*20];
    memset(p, 0, 1024*1024*20);
    for(int i=0; i<20; ++i) {
        sleep(10);
        test_part_virt(i%4);
    }
    getchar();
    return 0;
}
